--[[ -------------------------------------------------------
MUSHclient MiniWindow Flags.

$URL: http://mushclient-lua-objects.googlecode.com/svn/branches/working/Daesilme/MUSHclient/MiniWindow/Flags.lua $

Copyright (C) 2009 Daesilme (Daniel W. Drake)

This file is part of mushclient-lua-objects.

mushclient-lua-objects is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software
Foundation, either version 2 of the License, or (at your
option) any later version.

mushclient-lua-objects is distributed in the hope that it
will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.  See the GNU General Public License for
more details.

You should have received a copy of the GNU General Public
License along with mushclient-lua-objects.  If not, see
<http://www.gnu.org/licenses/>.
------------------------------------------------------- ]]--

require("class");
require("MUSHclient.Util.BitWise");

class "Flags";

local FlagsClass = Flags:classtable();

------------------------------------------------------------
-- PUBLIC CLASS PROPERTIES
------------------------------------------------------------

-- Possible Values for MiniWindow Flags
FlagsClass.NONE						=	0;
FlagsClass.DRAW_UNDERNEATH			=	1;
FlagsClass.ABSOLUTE_LOCATION		=	2;
FlagsClass.TRANSPARENT				=	4;
FlagsClass.ALL						=	7;
FlagsClass.NOT_DRAW_UNDERNEATH		=	6;
FlagsClass.NOT_ABSOLUTE_LOCATION	=	5;
FlagsClass.NOT_TRANSPARENT			=	3;

------------------------------------------------------------
-- PUBLIC CLASS METHODS
------------------------------------------------------------

-- Returns if the value @flags is a valid combination
-- of MiniWindow flags.
function FlagsClass:isValid(flags)
	return (
		(flags ~= nil)	and
		(flags >= 0)	and
		(flags < 8)
	);
end   -- FlagsClass:isValid(flags)

-- Returns a string representation of the MiniWindow Flags
-- specified by @flags.
function FlagsClass:toString(flags)
	local	str		=	"";

	if(
		BitWise:toBase10(
			BitWise:BWAnd(flags, self.TRANSPARENT)
		) == self.TRANSPARENT
	) then
		str = str .. "Transparent & ";
	end

	if(
		BitWise:toBase10(
			BitWise:BWAnd(flags, self.ABSOLUTE_LOCATION)
		) == self.ABSOLUTE_LOCATION
	) then
		str = str .. "Absolute Location & ";
	end

	if(
		BitWise:toBase10(
			BitWise:BWAnd(flags, self.DRAW_UNDERNEATH)
		) == self.DRAW_UNDERNEATH
	) then
		str = str .. "Draw Underneath & ";
	end

	if(str == "") then
		str = "NONE";
	else
		str = string.sub(str, 1, -4);
	end

	return str;

end

-- Returns if @flags has @test flag set.
function FlagsClass:isSet(flags, test)

	return	self:isValid(flags)	and
			self:isValid(test)	and
			BitWise:toBase10(
				BitWise:BWAnd(flags, test)
			) == test;

end   -- FlagsClass:isSet(flag, test)

------------------------------------------------------------
-- PUBLIC OBJECT PROPERTIES
------------------------------------------------------------

------------------------------------------------------------
-- PUBLIC OBJECT METHODS
------------------------------------------------------------

-- Constructor
-- Raises error to prevent instatiation
function Flags:initialize()
	error("MUSHclient.MiniWindow.Flags cannot be instantiated.");
end   -- Flags:initialize()

------------------------------------------------------------
-- PRIVATE CLASS PROPERTIES
------------------------------------------------------------

------------------------------------------------------------
-- PRIVATE CLASS METHODS
------------------------------------------------------------

------------------------------------------------------------
-- PRIVATE OBJECT PROPERTIES
------------------------------------------------------------

------------------------------------------------------------
-- PRIVATE OBJECT METHODS
------------------------------------------------------------
